function Student(id) {
    this.id = id;
    this.toString = function () {
        return this.id
    }
}
const stu = new Student(1)

//所有类的基类就是Object
// Object.prototype.toString()

console.log(stu.__proto__);
console.log(stu.toString());

// [array Array]
const array = new Array(1, 2, 3)
console.log(array.toString());

//[date Date]
const date = new Date()
console.log(date.toString());

console.log(Object.prototype.toString.call(stu));
console.log(Object.prototype.toString.call(array));
console.log(Object.prototype.toString.call(date));



function getType(obj) {
    let type = typeof obj;
    if (type !== "object") {    // 先进行typeof判断，如果是基础数据类型，直接返回
        return type;
    }
    // 对于typeof返回结果是object的，再进行如下的判断，正则返回结果
    return Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/, '$1');
}

console.log(getType(date));
console.log(getType(array));
